package com.tsmti.system.service.impl;

import com.tsmti.system.dao.NumberRuleDao;
import com.tsmti.system.entity.NumberRules;
import com.tsmti.system.service.NumberRuleService;
import com.tsmti.core.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

/**
 * Title：pims
 * Class：com.pims.service.impl.config
 * Comapny:杭州同烁软件信息技术有限公司
 *
 * @author：周陈伟
 * @version：2.5 CreateTime：2017/1/22 22:37
 * Modify log:
 * Description：
 */
@Service("numberRuleService")
public class NumberRuleServiceImpl extends BaseServiceImpl<NumberRules> implements NumberRuleService {
    @Autowired
    @Qualifier(value = "numberRuleDao")
    private NumberRuleDao numberRuleDao;
    @Override
    @Transactional(readOnly = true,rollbackFor = Exception.class)
    public Long getNumber(int type, String orgId) throws SQLException {
        return this.numberRuleDao.getNumber(type, orgId);
    }

    @Override
    @Transactional(readOnly = true,rollbackFor = Exception.class)
    public NumberRules getByType(Integer type, String orgId) {
        List<NumberRules> list = findByHql("from NumberRules where type=? and orgId=?", "" + type, orgId);
        if(list.size() > 0) {
            return  list.get(0);
        }
        return new NumberRules();
    }
}
